<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-tabs :activeKey="superParam.code" @change="tabChange">
        <a-tab-pane v-for="(item, index) in dictOptions" :key="item.value" :tab="item.text"> </a-tab-pane>
      </a-tabs>
      <a-form layout="inline" @keyup.enter.native="searchList">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="机构名称">
              <j-select-depart
                v-model="queryParam.officeId"
                :trigger-change="true"
                customReturnField="id"
                :multi="false"
              ></j-select-depart>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="年度">
              <a-date-picker
                mode="year"
                placeholder="请选择年份"
                format="YYYY"
                value-format="yyyy-MM-dd"
                v-model="queryParam.year"
                :open="yearPickShow"
                style="width: 100%"
                @panelChange="handlePanelChange"
                @openChange="handleOpenChange"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="季度">
              <j-dict-select-tag
                style="width: 100%"
                v-model="queryParam.quarter"
                placeholder="请选择"
                dict-code="sys_quarter"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchList" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">清除条件</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        v-if="superParam.code == '6' || superParam.code == '7'"
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columnsTransfer"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <span slot="create" slot-scope="text, record">
          {{ record.createByText || record.realName }}
        </span>
        <span slot="ifstate" slot-scope="text, record">
          {{ record.status_dictText || record.isMerge_dictText }}
        </span>
        <span slot="applystate" slot-scope="text, record">
          {{ record.applystate_dictText || record.state_dictText }}
        </span>
        <template slot="departName" slot-scope="departName">
          <div style="width: 100%; height: 35px; line-height: 35px; overflow-x: hidden; overflow-y: auto">
            {{ departName }}
          </div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleApprove(record, title)">审批</a>
        </span>
      </a-table>
      <a-table
        v-else
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <span slot="create" slot-scope="text, record">
          {{ record.createByText || record.realName }}
        </span>
        <span slot="ifstate" slot-scope="text, record">
          {{ record.status_dictText || record.isMerge_dictText }}
        </span>
        <span slot="applystate" slot-scope="text, record">
          {{ record.applystate_dictText || record.state_dictText }}
        </span>
        <template slot="departName" slot-scope="departName">
          <div style="width: 100%; height: 35px; line-height: 35px; overflow-x: hidden; overflow-y: auto">
            {{ departName }}
          </div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleApprove(record, title)">审批</a>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <component v-bind:is="ModelView" ref="modalForm" @ok="updateProList"></component>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ModelView1 from './ModelView/ModelView1'
import ModelView2 from './ModelView/ModelView2'
import ModelView3 from './ModelView/ModelView3'
import ModelView4 from './ModelView/ModelView4'
import ModelView5 from './ModelView/ModelView5'
import ModelView6 from './ModelView/ModelView6'
import ModelView7 from './ModelView/ModelView7'
import ModelView8 from './ModelView/ModelView8'
import ModelView9 from './ModelView/ModelView9'
import ModelView10 from './ModelView/ModelView10'
import ModelView11 from './ModelView/ModelView11'
import ModelView12 from './ModelView/ModelView12'
import moment from 'moment'
import 'moment/locale/zh-cn'
import columns from './indexColumns'
import columnsTransfer from './columnsTransfer'
import creatReport from './creatReport'
import { ajaxGetDictItems } from '@/api/api'

export default {
  name: 'bbsb',
  mixins: [JeecgListMixin],
  components: {
    creatReport,
    ModelView1,
    ModelView2,
    ModelView3,
    ModelView4,
    ModelView5,
    ModelView6,
    ModelView7,
    ModelView8,
    ModelView9,
    ModelView10,
    ModelView11,
    ModelView12,
  },
  data() {
    return {
      dictOptions: [],
      queryParam: {
        year: '',
      },
      superParam: {
        code: '1',
        type: '1',
        state: '1',
        applystate: '2',
        sjType: '',
      },
      // 表头
      columns: columns(this),
      columnsTransfer: columnsTransfer(this),
      url: {
        list: '/sjxxzhgl/sjProjectReport/queryProjectReportFront',
      },
      yearPickShow: false,
      title: '审计项目实施情况统计表(季报)',
      modelNum: '1',
      disableMixinCreated: true,
    }
  },
  computed: {
    ModelView: function () {
      return 'ModelView' + this.modelNum
    },
  },
  watch: {
    modelNum(val) {
      switch (val) {
        case '1':
          this.title = '审计项目实施情况统计表(季报)'
          break
        case '2':
          this.title = '审计发现问题分类统计表(季报)'
          break
        case '3':
          this.title = '单位情况信息表(季报)'
          break
        case '4':
          this.title = '总审计师与内部审计机构基本情况表(季报)'
          break
        case '5':
          this.title = '内部审计人员配备情况表(季报)'
          break
        case '6':
          this.title = '抽调审计人员费用统计表'
          break
        case '7':
          this.title = '单位及内部审计机构基本情况表'
          break
        case '8':
          this.title = '单位内部审计业务情况表'
          break
        case '9':
          this.title = '审计署报送报表情况统计'
          break
        case '10':
          this.title = '中央企业内部审计工作情况统计表'
          break
        case '11':
          this.title = '中央企业内部审计发现问题汇总表'
          break
        case '12':
          this.title = '审计境外项目情况表'
          break
        default:
          break
      }
    },
    'superParam.code': {
      handler: function (val) {
        if (val) {
          // debugger
          this.searchList()
          if (this.queryParam.id) delete this.queryParam.id
        }
      },
      // immediate: true,
    },
    $route: {
      handler: function (to) {
        if (to.query.code && to.query.id) {
          this.disableMixinCreated = true
          this.superParam.code = to.query.code
          this.queryParam.id = to.query.id
          // debugger
          this.searchList()
          // debugger
        }
      },
    },
  },
  created() {
    this.tabsData()
    this.searchList()
  },
  methods: {
    tabChange(activeKey) {
      this.superParam.code = activeKey
    },
    tabsData() {
      ajaxGetDictItems('report_tab_menu_sp', null).then((res) => {
        if (res.success) {
          this.dictOptions = res.result
        }
      })
    },
    // 查询条件
    searchList() {
      if (this.superParam.code == '1' || this.superParam.code == '2') {
        this.superParam.type = this.superParam.code
        this.queryParam.status = 2
        this.url.list = '/sjxxzhgl/sjProjectReport/queryProjectReportFront'
      } else if (this.superParam.code == '6') {
        this.superParam.sjType = '4'
        this.url.list = '/sjxxzhbb/sjAuditInfo/queryAuditorInfoBehind' //sjxxzhbb/sjAuditSummaryInfo/queryAuditCostInfoList
      } else if (this.superParam.code == '7') {
        this.superParam.sjType = '5'
        this.url.list = '/sjxxzhbb/sjAuditInfo/queryAuditorSJSOneDA' //sjxxzhbb/sjAuditSummaryInfo/queryAuditCostInfoList
      } else if (this.superParam.code == '8') {
        this.superParam.sjType = '6'
        this.url.list = '/sjxxzhbb/sjAuditInfo/querySJSTwoReportDA'
      } else if (this.superParam.code == '9') {
        this.superParam.sjType = '7'
        this.url.list = '/sjxxzhbb/sjsbb/queryReportBsbbqktjDA'
      } else if (this.superParam.code == '10') {
        this.superParam.sjType = '8'
        this.url.list = '/sjxxzhbb/sjAuditInfo/queryGZWOneReportDA'
      } else if (this.superParam.code == '11') {
        this.superParam.sjType = '9'
        this.url.list = '/sjxxzhbb/gzwbb/queryReportNbsjfxwthzDA'
      } else if (this.superParam.code == '12') {
        this.superParam.sjType = '10'
        this.url.list = '/sjxxzhbb/gzwbb/queryReportNbsjfxwthzDA'
      } else {
        this.superParam.sjType = String(Number(this.superParam.code) - 2)
        this.url.list = '/sjxxzhbb/sjAuditInfo/queryAuditorInfoBehind'
      }
      this.modelNum = this.superParam.code
      this.loadData(1)
    },

    // 年份选择器 begin
    moment,
    // 得到年份选择器的值
    handlePanelChange(value) {
      this.yearPickShow = false
      this.queryParam.year = moment(value).format('YYYY')
    },
    // 弹出日历和关闭日历的回调
    handleOpenChange(status) {
      this.yearPickShow = status
      if(this.queryParam.year){
        this.queryParam.year = moment(this.queryParam.year.slice(0, 4)).format('YYYY')
      }
    },
    // 年份选择器 end

    // 操作按钮
    handleApprove: function (record, name) {
      this.$refs.modalForm.approve(record)
      this.$refs.modalForm.title = name
      this.$refs.modalForm.isCheck = true
      this.$refs.modalForm.disableSubmit = true
    },
    updateProList() {
      this.loadData()
    },
  },
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';

.bbsbtype {
  /deep/ .ant-form-item-label {
    label::before {
      content: '* ';
      color: red;
    }
  }
}
</style>